<template>
  <!-- 1普通输入2日期输入3时间输入4操作5选择框 -->
  <el-row >
    <el-button type="primary" @click="addData">添加</el-button>
    <el-button type="primary" v-if='flag' @click="handleTwClick">保存</el-button>
     <el-table :height="height"  :data="tableData" style="width: 100%;">
      <template v-for="(item, index) in tableTitle">
        <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 1"
          :key="index"
          :width="item.width">
          <template slot-scope="scope">
            <el-input v-model="scope.row[item.prop]" placeholder="请输入内容"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 2"
          :key="index"
          :width="item.width + 30">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row[item.prop]"
              align="right"   
              type="date" 
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
             >
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 3"
          :key="index"
          :width="item.width + 30">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row[item.prop]"
              type="datetime"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="选择时间">
            </el-date-picker>
          </template>
        </el-table-column>
        
        <el-table-column
            :width="item.width"
            :fixed="item.fixed"
            v-if="item.type == 4"
            :prop="item.prop"
            label="操作"
            :key="index"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit(it.number, scope.$index,scope.row)"
                v-for="it in item.arr"
                :type="it.flag != 2? it.type: scope.row.status == 1? 'danger': 'success'"
                :key="it.number"
              >
                {{it.name}}
              </el-button>
            </template>
        </el-table-column>
         <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 5"
          :key="index"
          :width="item.width + 30">
          <template slot-scope="scope">
            <el-select v-model="scope.row[item.prop]" placeholder="请选择">
              <el-option
                v-for="item in item.arr"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 6"
          :key="index"
          :width="item.width + 30">
          <template slot-scope="scope">
            <el-select v-model="scope.row[item.prop]" placeholder="请选择">
              <el-option
                v-for="item in item.arr"
                :key="item.name"
                :label="item.name"
                :value="item.name">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          :prop="item.prop"
          :label="item.name"
          v-if="item.type == 7"
          :key="index"
          :width="item.width + 30">
          <template slot-scope="scope">
            <el-select v-model="scope.row[item.prop]" placeholder="请选择">
              <el-option
                v-for="item in item.arr"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
      </template>
    </el-table>
  </el-row>
</template>

<script>
import {deleteNurseSheet,deleteTemperature} from "@/api/hospitalNurse"

export default {
  data(){
    return {
      height:0
    }
  },
  watch:{
    tableData(to,q){
      console.log(to.length)
      if(to.length >= 4){
        this.height = 320
      }else{
        this.height = (to.length+1) * 65
      }
    },
   
  },
  mounted(){
    
  },
  methods:{
   addData(){
      if(this.type == 1){
        let data = {
          id:0,
          nurse_time:"",
          time_id:"",
          t_time:"",
          ys:"",
          tw:"",
          mb:"",
          hx:"",
          xy:"",
          xyuan:"",
          rl_extraName:"",
          rl_extraMl:"",
          cl_extraName:"",
          cl_extraMl:"",
          cl_extraColor:"",
          xyan:"",
          xy_extraBdg:"",
          xy_extraMz:"",
          gl_nurse:"",
          xuejiao:"",
          guancha:"",
          nurse_name:"",
          nurse_level:"",
          t_time:[],
        }
        this.tableData.push(data)
      }else if(this.type == 2){
        let data = {
          id:0,
          type:"",
          t_date:"",
          tiwen:"",
          maibo:"",
          huxi:"",
          xinlv:"",
          wljw:"",
          wenzhu:"",
          remark:"",
          shoushu_day:"",
          mmhg_zao:"",
          mmhg_zhong:"",
          mmhg_wan:"",
          dabian:"",
          xiaobian:"",
          niaoliang:"",
          qita:"",
          day_chu:"",
          day_ru:"",
          weight:"",
          height:"",
          skin:"",
          fuwei:"",
          t_time:"",
        }
        this.tableData.push(data)
      }
   },
   handleTwClick(){
    this.$emit("handleTwClick",this.tableData)
   },
   handleEdit(e,q,data){
     console.log(e,q,data)
     if(data.id != ""){
      this.$confirm('你确定删除么', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
        }).then(() => {
          if(this.type == 1){
              deleteNurseSheet({id:data.id})
              .then(res=>{
                this.tableData.splice(q,1)
                this.$message({
                  message:"删除成功",
                  type: 'success'
                });
              })
              .catch(e=>{
                this.$message({
                  message:e.message,
                  type: 'error'
                });
              })
          }else if(this.type == 2){
            deleteTemperature({id:data.id})
            .then(res=>{
              this.tableData.splice(q,1)
              this.$message({
                message:"删除成功",
                type: 'success'
              });
            })
            .catch(e=>{
              this.$message({
                message:e.message,
                type: 'error'
              });
            })
          }
          
        })
     }else{
        this.tableData.splice(q,1)
     }
   
   },
  },
  props: {
    tableTitle: {
      type: Array,
      default: "",
    },
    type:{
      type: [Number, String],
      default: "",
    },
    tableData: {
      type: Array,
      default: [],
    },
    flag: {
      type: Boolean,
      default:false
    }
  },
}
</script>

<style>

</style>